/*************************************************
 *FileName:      myfans.js
 *Description:   我的粉丝.js
 *Others:        陈灿
 *************************************************/
/*
 * 启动
 */
mui.init();
/*
 * 变量初始化
 */
var uid = localStorage.replace_uid;
var token = localStorage.replace_token;
var ohtml = '';
/*
 * 主程序
 */
    mui.init({
        beforeback: function() {
            var list = plus.webview.currentWebview().opener();
            mui.fire(list, 'refreshindex');
            return true;
        }
    });
$(document).ready(function() {
    //样式加载
    pagecss();
    //获取用户信息
});
/**
 * pagecss
 * 样式加载
 * @cc 
 * @DateTime 2018-01-08T06:19:16+0800
 * @param    int        
 * @return   void
 */
function pagecss() {
    mui.plusReady(getlist)
    $('.mui-scroll').attr('style', 'transform: translate3d(0px, 0px, 0px) translateZ(0px); transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms;')
    var onav = '';
    for(var i = 0; i < 26; i++) {
        onav += '<a data-id="' + String.fromCharCode(97 + i) + '">' + String.fromCharCode(65 + i) + '</a>'
    }
    $('.nav .top').after(onav); //字母输出

    $('.nav a').on('tap', function() {
        var oheader = $('header.mui-bar').height() + $('.serch').height() + $('.title').height();
        var obj = '#' + $(this).attr('data-id');
        if(!$('.main').find($(obj)).length){return false;}
        var distance = -common.getTop($(obj)[0]) //计算高度
        var osum = distance + oheader;
        mui('.mui-scroll-wrapper').scroll().scrollTo(0, osum, 100);
    }) //字母跳转
    
    $('.main').on('tap','.userimg',function(){
        var oid = $(this).parents('.mf-table-view-cell').attr('data-id');
        common.pageTransition('personal.html?friend_uid='+oid)  
    })
    
    $('.mui-scroll-wrapper').on('tap',function(){
        $('input').blur()
    })
    
    $('.serch-input').focusin(function() {
        $('.title').css({
            display: 'none'
        });
        if(!$(this).val()) {
            $('.mf-table-view-cell').css({
                display: 'none'
            })
        }
        $('nav.nav').css({
            display: 'none'
        });
    }).on('input', function() {
        $('.mf-table-view-cell').css({
            display: 'none'
        })
        if($(this).val()) {
            for(var i = 0; i < $('.mf-table-view-cell').length; i++) {
                otext = $(this).val();
                Cts = $('.mf-table-view-cell').eq(i).find('.user').text() + $('.mf-table-view-cell').eq(i).find('.phone').text();
                Cts.indexOf(otext) > -1 ? $('.mf-table-view-cell').eq(i).css({
                    display: '-webkit-flex'
                }) : false;
            }
        }
    }).focusout(function() {
        if(!$(this).val()) {
            $('.title').css({
                display: 'block'
            });
            $('.mf-table-view-cell').css({
                display: '-webkit-flex'
            });
            $('nav.nav').css({
                display: 'block'
            });
        }
    }) //搜索效果

    $('.nav .top').on('tap', function() {
        mui('.mui-scroll-wrapper').scroll().scrollTo(0, 0, 100); //100毫秒滚动到顶
    }) //置顶
    $('.nav .bottom').on('tap', function() {
        mui('.mui-scroll-wrapper').scroll().scrollToBottom(0, 0, 100); //100毫秒滚动到顶
    }) //置低
    
}
/**
 * adds //方法名
 * @陈灿 //作者名
 * @DateTime 2018-01-010T0116:25:00+0800 //时间
 * @param    int    $goods_id //参数
 * @param    array  $data //参数
 * @return    array  [error_code, error_msg, goods_id] //返回值
 */

//获取用户信息
function getlist() {
    $.ajax({
        type: "post",
        url: DOMAIN_NAME + "/index.php/api/users_attention/attentionMeList",
        dataType: 'jsonp',
        data: {
            uid: uid,
            token: token
        },
        success: function(data) {
            if(data.error_code == 0) {
                for(var i = 0; i < data.data.length; i++) {
                    var su,sn = data.data[i].text;
                    data.data[i].text == '' ?su = '#':su = data.data[i].text;
                    ohtml += '<a class="title" id="' + sn.toLowerCase() + '">' + su + '</a>';
                    for(var j = 0; j < data.data[i].data.length; j++) {
                        ohtml += '<a class="mf-table-view-cell" data-id="' + data.data[i].data[j].uid + '"><div class="userimg">';
                        data.data[i].data[j].uid_new ? ohtml += '<em class="new"></em>' : ohtml += '';
                        ohtml += '<img onerror="imgExists(this)" src="'+DOMAIN_NAME + data.data[i].data[j].face + '"/>' +
                            '</div><div class="mf-navigate-right">' +
                            '<div class="user">' + data.data[i].data[j].nickname + '</div><div class="age">';
                        data.data[i].data[j].sex == 'woman' ? ohtml += '<img src="images/icon_girl.png"/>' : ohtml += '<img src="images/icon_boy.png"/>';
                        ohtml += '<span>' + data.data[i].data[j].age + '</span></div>';
                        data.data[i].data[j].level ? ohtml += '<div class="age sex"><span>' + data.data[i].data[j].level + '级魅力</span></div></div></a>' : ohtml += '</div><i class="mui-icon mui-icon-arrowright arrows"></i></a>';
                    }
                }
                $('.main').html(ohtml);
            } else if(data.error_code == 1001) {
                setTimeout(function(){
                    exitlogin();
                },1000);
            } else {

            }
            mui('.mui-scroll-wrapper').scroll({
                indicators: false, //是否显示滚动条 默认为true
                deceleration: 0.003, //阻尼系数,系数越小滑动越灵敏 默认0.0006
                bounce: true //是否启用回弹 默认true
            });
        }
    });
}